import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    uid: window.sessionStorage.getItem('uid'),  // user id
    cid: window.sessionStorage.getItem('cid'),  // craftsman id
    user: window.sessionStorage.getItem('user'),
    token: window.sessionStorage.getItem('token'),
    avatar: window.sessionStorage.getItem('avatar'),
    verified: window.sessionStorage.getItem('verified'),
  },
  mutations: {
    setToken: (state,data) => {
      state.token = data;
      window.sessionStorage.setItem('token',data)
    },
    setUser: (state,data) => {
      state.user = data;
      window.sessionStorage.setItem('user',data)
    },
    setUid: (state,data) => {
      state.uid = data;
      window.sessionStorage.setItem('uid',data)
    },
    setCid: (state,data) => {
      state.cid = data;
      window.sessionStorage.setItem('cid',data)
    },
    setAvatar: (state,data) => {
      state.avatar = data;
      window.sessionStorage.setItem('avatar',data)
    },
    setVerified: (state,data) => {
      state.verified = data;
      window.sessionStorage.setItem('verified',data)
    },
    logout: (state) => {
      state.avatar = null;
      state.token = null;
      state.user = null;
      state.uid = 0;
      state.cid = 0;
      state.verified = 0;
      window.sessionStorage.removeItem('user');
      window.sessionStorage.removeItem('uid');
      window.sessionStorage.removeItem('cid');
      window.sessionStorage.removeItem('token');
      window.sessionStorage.removeItem('avatar');
      window.sessionStorage.removeItem('verified');
    }
  },
  actions: {
  },
  modules: {
  }
})
